<div id="grantPage">
	<div id="grantTitle">权限管理</div>
	<hr />
	<?php
	  echo $this->Html->css('grant');
	  echo $this->Session->flash('auth'); 
	  echo $this->Session->flash(); 
	?>
	<div>
		<div id="userList">
			<div class="title">当前管理员</div>
			<form method="POST" onsubmit="beforeDel();return false;">
				<input type="hidden" name="userid" id="userid"/>
				<input type="hidden" name="action" value="del" />
				<ul id="powerUsers">
					<?php
					foreach ($users as $user) {
						echo "<li userid='{$user['User']['id']}'>{$user['User']['username']}</li>";
					}?>
				</ul>
				<input type="submit" id="del" value="移除管理员权限"/>
			</form>
		</div>
		<div id="addPowerUser">
			<div class="title">添加新管理员</div>
			<form method="POST">
				<span>请填写新管理员用户名：</span><input type="text" name="username" required/>
				<input type="hidden" name="action" value="add" />
				<input type="submit" id="add" value="添加管理员"/>
				<hr />
				<div><p>管理员可以删除评论，修改不合理的食谱或者删除食谱，您不能将自己从管理员里删除。</p></div>
			</form>
		</div>
		<div id="report"><div class="title">网站信息</div><p>会员数：<span><?php echo $report['usersNumber']; ?></span></p><p>发表食谱数：<span><?php echo $report['recipesNumber']; ?></span></p><p>评论数：<span><?php echo $report['commentsNumber']; ?></span></p></div>
		<div class="clearFix"></div>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		

		$("#powerUsers li").click(function(){
			var userid = $(this).attr('userid');
			$("#userid").val(userid);
			$(".focusUser").removeClass("focusUser");
			$(this).addClass("focusUser");
		});
	});
	
	var my_id = <?php echo $_SESSION['userid']; ?>;

	function beforeDel() {
		var userid = $(".focusUser").eq(0).attr("userid");

		if (userid){
			if (userid == my_id){
				alert("您不能删除自己的权限");
				return false;
			}else{
				return true;
			}					
		}else{
			alert("您还没有选择操作的用户");
		}

		return true;
	}
</script>